import pandas as pd


class Player():
    def __init__(self, name, money, physical) :
        #if self.load_data():
           # return
        
        self.name = name
        self.money = money
        self.physical = physical
        #self.pet_list = pet_list

    def load_data(self, file_path="v-pet./data./player_data.csv"):
        try:
            data = pd.read_csv(file_path)
            row = data.iloc[0]
            self.name = row["name"]
            self.money = row["money"]
            self.physical = row["physical"]
            #self.pet_list = row["pet_list"].split(",")
            return True
        except Exception as e:
            print("加载用户数据异常:\n"+str(e))
            return False
        
    def save_data(self, file_path = "v-pet./data./player_data.csv") :
        player_data = {
            'name' : [self.name],
            'money' : [self.money],
            'physical' : [self.physical]
            #'pet_list' : self.pet_list
        }
        df = pd.DataFrame(player_data)
        df.to_csv(file_path, index=True)
        print("玩家数据已保存到", file_path)
        
        